{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "votes = pd.read_csv(\"114_congress.csv\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "R    54\n",
      "D    44\n",
      "I     2\n",
      "Name: party, dtype: int64\n",
      "00001    0.325\n",
      "00004    0.575\n",
      "00005    0.535\n",
      "00006    0.945\n",
      "00007    0.545\n",
      "00008    0.415\n",
      "00009    0.545\n",
      "00010    0.985\n",
      "00020    0.525\n",
      "00026    0.545\n",
      "00032    0.410\n",
      "00038    0.480\n",
      "00039    0.510\n",
      "00044    0.460\n",
      "00047    0.370\n",
      "dtype: float64\n"
     ]
    }
   ],
   "source": [
    "print(votes[\"party\"].value_counts())\n",
    "print(votes.mean())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[ 1.73205081]]\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "e:\\python27\\lib\\site-packages\\ipykernel\\__main__.py:3: FutureWarning: reshape is deprecated and will raise in a subsequent release. Please use .values.reshape(...) instead\n",
      "  app.launch_new_instance()\n",
      "e:\\python27\\lib\\site-packages\\ipykernel\\__main__.py:4: FutureWarning: reshape is deprecated and will raise in a subsequent release. Please use .values.reshape(...) instead\n"
     ]
    }
   ],
   "source": [
    "from sklearn.metrics.pairwise import euclidean_distances\n",
    "\n",
    "print(euclidean_distances(votes.iloc[0,3:].reshape(1, -1), votes.iloc[1,3:].reshape(1, -1)))\n",
    "distance = euclidean_distances(votes.iloc[0,3:].reshape(1, -1), votes.iloc[2,3:].reshape(1, -1))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "from sklearn.cluster import KMeans\n",
    "\n",
    "kmeans_model = KMeans(n_clusters=2, random_state=1)\n",
    "senator_distances = kmeans_model.fit_transform(votes.iloc[:, 3:])\n",
    "#print senator_distances"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "party   D  I   R\n",
      "row_0           \n",
      "0      41  2   0\n",
      "1       3  0  54\n"
     ]
    }
   ],
   "source": [
    "\n",
    "labels = kmeans_model.labels_\n",
    "print(pd.crosstab(labels, votes[\"party\"]))\n",
    "democratic_outliers = votes[(labels == 1) & (votes[\"party\"] != \"D\")]\n",
    "#print(democratic_outliers)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "        name party state  00001  00004  00005  00006  00007  00008  00009  \\\n",
      "42  Heitkamp     D    ND    0.0    1.0    0.0    1.0    0.0    0.0    1.0   \n",
      "56   Manchin     D    WV    0.0    1.0    0.0    1.0    0.0    0.0    1.0   \n",
      "74      Reid     D    NV    0.5    0.5    0.5    0.5    0.5    0.5    0.5   \n",
      "\n",
      "    00010  00020  00026  00032  00038  00039  00044  00047  \n",
      "42    1.0    0.0    0.0    0.0    1.0    0.0    0.0    0.0  \n",
      "56    1.0    1.0    0.0    0.0    1.0    1.0    0.0    0.0  \n",
      "74    0.5    0.5    0.5    0.5    0.5    0.5    0.5    0.5  \n"
     ]
    }
   ],
   "source": [
    "democratic_outliers = votes[(labels == 1) & (votes[\"party\"] == \"D\")]\n",
    "print(democratic_outliers)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAgsAAAFkCAYAAACuFXjcAAAABHNCSVQIC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klwJJKTR+aWQegCEiLi4zkf2XAeD4GHA/0SHYhNaxa/Uzj8VxE6Fx1NqHVcyeZ2eke\nP0TTWbX7mo7jaWZtCQXbPs658kQeO9EzC4l6EFUqiKWvB/IxcEy8ikoB6Tqe8ZIW42lmjwDnAWc4\n59YeZPO0HdMo+3kgKT+ezrkK59xy59x859zthC6IG1PF5mk7lhB1Xw8k1cczH2gJlJpZuZmVE7r2\nYoyZ7Q3PkkWKy5gmNCyEk9C+B1EB+z2IqqqHXnxQefswzwdRpYIY+3ogXQlNl2WKtBzPOEr58Qz/\nAL0IONM59201dknLMY2hnweS8uN5AD6gqunntBxLD159PZBUH89ZwEmE6uwSfn0KPAN0CV8XFyk+\nY5qEqzgvBXYCVwHHAX8jdMVqy/DnfwImVtq+PbCN0BWdxxK6bW0voWmYpF+VGue+jgEuBDoAJxCa\nbion9FtP0vtTRR8bhf/CdiV0NflN4fftMnA8o+1rOo7nY8APhG4tbFXpVb/SNvek+5jG2M90HM97\nwn08Ejgx/He0Ajirir+zaTeWh9DXtBvPKvq9390QNfXfZ7I6dz3wDbCLULo5udJnTwGzI7Y/ndBv\n6buAr4Erkz1ANdFX4P+G+7cD2EjoTorTk92Hg/SvF6EfnIGI14RMG89o+5qm43mg/gWAqyptk/Zj\nGks/03Q8nwCWh8dlHTCD8A/PTBnLWPuajuNZRb9ns39YqJEx1YOkRERExJOeDSEiIiKeFBZERETE\nk8KCiIiIeFJYEBEREU8KCyIiIuJJYUFEREQ8KSyIiIiIJ4UFERER8aSwICIiIp4UFkRERMSTwoKI\niIh4+v+N14JNufYK5QAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x88620d0>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "import matplotlib.pyplot as plt\n",
    "plt.scatter(x=senator_distances[:,0], y=senator_distances[:,1], c=labels)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "39.317824\n",
      "25.576\n"
     ]
    }
   ],
   "source": [
    "extremist = [3.4, .24]\n",
    "moderate = [2.6, 2]\n",
    "print 3.4 ** 3 + .24 ** 3\n",
    "print 2.6 ** 3 + 2 ** 3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "         name party state  00001  00004  00005  00006  00007  00008  00009  \\\n",
      "98     Wicker     R    MS    0.0    1.0    1.0    1.0    1.0    0.0    1.0   \n",
      "53   Lankford     R    OK    0.0    1.0    1.0    0.0    1.0    0.0    1.0   \n",
      "69       Paul     R    KY    0.0    1.0    1.0    0.0    1.0    0.0    1.0   \n",
      "80      Sasse     R    NE    0.0    1.0    1.0    0.0    1.0    0.0    1.0   \n",
      "26       Cruz     R    TX    0.0    1.0    1.0    0.0    1.0    0.0    1.0   \n",
      "48    Johnson     R    WI    0.0    1.0    1.0    1.0    1.0    0.0    1.0   \n",
      "47    Isakson     R    GA    0.0    1.0    1.0    1.0    1.0    0.0    1.0   \n",
      "65  Murkowski     R    AK    0.0    1.0    1.0    1.0    1.0    0.0    1.0   \n",
      "64      Moran     R    KS    0.0    1.0    1.0    1.0    1.0    0.0    1.0   \n",
      "30       Enzi     R    WY    0.0    1.0    1.0    1.0    1.0    0.0    1.0   \n",
      "\n",
      "    00010  00020  00026  00032  00038  00039  00044  00047  extremism  \n",
      "98    0.0    1.0    1.0    0.0    0.0    1.0    0.0    0.0  46.250476  \n",
      "53    1.0    1.0    1.0    0.0    0.0    1.0    0.0    0.0  46.046873  \n",
      "69    1.0    1.0    1.0    0.0    0.0    1.0    0.0    0.0  46.046873  \n",
      "80    1.0    1.0    1.0    0.0    0.0    1.0    0.0    0.0  46.046873  \n",
      "26    1.0    1.0    1.0    0.0    0.0    1.0    0.0    0.0  46.046873  \n",
      "48    1.0    1.0    1.0    0.0    0.0    1.0    0.0    0.0  40.017540  \n",
      "47    1.0    1.0    1.0    0.0    0.0    1.0    0.0    0.0  40.017540  \n",
      "65    1.0    1.0    1.0    0.0    0.0    1.0    0.0    0.0  40.017540  \n",
      "64    1.0    1.0    1.0    0.0    0.0    1.0    0.0    0.0  40.017540  \n",
      "30    1.0    1.0    1.0    0.0    0.0    1.0    0.0    0.0  40.017540  \n"
     ]
    }
   ],
   "source": [
    "\n",
    "extremism = (senator_distances ** 3).sum(axis=1)\n",
    "votes[\"extremism\"] = extremism\n",
    "votes.sort_values(\"extremism\", inplace=True, ascending=False)\n",
    "print(votes.head(10))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.11"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
